WASTE TCL 2.0
A TCL wrapper class for WASTE
By Dan Crevier
6/16/96
Overview
Introduction
WASTE is a TextEdit replacement by Marco Piovanelli that adds many features such as
>32k text support, drag and drop support, undo support, and so on. For information on WASTE, see
the WASTE page.
Just as WASTE is meant to be an easy replacement for TextEdit with additional features,
CWASTEText is meant to be an easy replacement for the CStyleText class in TCL,
adding support for WASTE's additional capabilities.
The classes included in WASTE TCL are:
- CWASTEText
- A subclass of CAbstractText, and is meant to serve as a replacement for CStyleText
- CWASTEDlgText.
- A subclass of CWASTEText, which has much of the same functionality of CDialogText,
except for the validation features.
- CWASTETask
- A CTask subclass for handling undo.
- CWASTEClipboard
- A replacement for CClipboard that uses WASTE.
- CTSMSwitchboard
- A CSwitchboard subclass that adds support for inline input.
- CTSMDesktop
- A CDesktop subclass that adds support for inline input.
- CWASTEEditTask and CWASTEStyleTask
- Only needed if you are using WASTE 1.0.
Requirements
WASTE-TCL is primarily intended for use with WASTE 1.2 and TCL 2.0, but it should also
work with WASTE 1.0 or 1.1, or with TCL 1.1. It optionally supports the WASTE Object
Archive, and the WASTE Tab code. There are many permutations of options that it should
work with, but I have not been able to test them all.
Usage
These classes are provided as public domain. You are free to use them as you see fit.
I only request that if you find any bugs or add any features that you let me know
so that they can be fixed in a future release.
Adding Support For WASTE TCL
Adding Inline input support
Inline input allows users of systems that use front end processors (such as Japanese and
Chinese systems) to input the text directly into their document rather than using
a floating window. It requires very little work to add this support, so I recommend
doing it. Since things get more complicated when you use the CApplication constructor
with arguments, I suggest using the IApp approach. In this case, you'll need to add
the following includes:
#include "WASTE.h"
#ifndef __SCRIPT__
#include <Script.h>#endif
#include "CTSMSwitchboard.h"
#include "CTSMDesktop.h"
static Boolean TSMAvailable(void);
extern CDesktop *gDesktop;
and add the following global variable:
Boolean gUsingTSM = false;
in your IApp() function, add:
gUsingTSM = TSMAvailable() && (InitTSMAwareApplication()==noErr);
In the destructor, add:
if (gUsingTSM) CloseTSMAwareApplication();
Also add the following functions:
// make TSMSwitchboard
void CEditApp::MakeSwitchboard(void)
{
if (gSystem.hasAppleEvents && gUsingTSM)
{
FailOSErr(WEInstallTSMHandlers());
}
itsSwitchboard = (CSwitchboard *)new CTSMSwitchboard();
itsSwitchboard->InitAppleEvents(); // needed for TCL 2.0.3
}
// make TSMDesktop
void CEditApp::MakeDesktop(void)
{
gDesktop = (CDesktop *)new CTSMDesktop();
}
/******************************************************************************
TSMAvailable - returns true if the TextService Manager is available
******************************************************************************/
static Boolean TSMAvailable(void)
{
long response;
return (Gestalt(gestaltTSMgrVersion, &response)==noErr);
}
Adding Drag and Drop support
You don't have to do any work to make it so that users can drag text out of CWASTEText
panes. If you want to let the user drag text into a CWASTEText pane, you should call
CWASTEText::InstallDragHandlers() for that pane. Note: you cannot call
InstallDragHandlers() for more than one CWASTEText pane per window.
Before you can call InstallDrag Handlers, you must add the following to your
application class:
#include <Drag.h>
static Boolean DragAndDropAvailable(void);
Boolean gHasDragAndDrop = false;
In the IApp() function, add:
gHasDragAndDrop = DragAndDropAvailable();
And add the function:
/******************************************************************************
DragAndDropAvailable - returns true if drag and drop is available
******************************************************************************/
static Boolean DragAndDropAvailable(void)
{
long response;
if (Gestalt(gestaltDragMgrAttr, &response) != noErr) return false;
if ((response & (1 << gestaltDragMgrPresent)) == 0) return false;
if ((Ptr)InstallTrackingHandler == kUnresolvedSymbolAddress) return false;
return true;
}
Finally, you must add the string "Drag" to STR# resource 130 so you get the
"Undo Drag" message in the edit menu.
Adding support for CWASTEClipboard
Override the following function in your application class:
/******************************************************************************
MakeClipboard
Create the global Clipboard object
******************************************************************************/
void CEditApp::MakeClipboard(void)
{
CWASTEClipboard *wasteClip = TCL_NEW(CWASTEClipboard,(true));
gClipboard = wasteClip;
}
Object support
CWASTEText includes handlers for pictures and sounds. You need to add the file
"Sound Icon.rsrc" to your project.
CWASTEText specific functions
The following functions are found in CWASTEText, but not CStyleText:
- Clear()
- Clears the text without any excess highlighting.
- CopyRangeWithStyle()
- Copies the text and style of a range.
- CopyRangeWithStyleSoup()
- Copies the text, style, and soup of a range.
- GetChar()
- Gets the character at the given offset.
- GetRunInfo()
- Gets the WERunInfo structure for the given run offset.
- InsertWithStyle()
- Inserts text along with style information.
- InsertWithStyleSoup()
- Inserts text along with style and soup information.
- InsertPicture()
- Inserts a picture at the current insertion point.
- InsertSound()
- Inserts a sound at the current insertion point.
- InstallDragHandlers()
- Sets the pane of for receiving drags.
- InstallTabHandlers()
- Installs hooks for the pane to use the tab code.
- ReadFromFile()
- Reads from a CDataFile into the pane
- RemoveDragHandlers()
- Makes it so the pane won't receive drags.
- ScrollToRange()
- Scrolls a range into view
- SetFontColor()
- Sets the color of the selection.
- SetFontColorAll()
- Sets the color of all of the text, by name.
- SetFontNameAll()
- Sets the font of all of the text, by name.
- SetFontNumberAll()
- Sets the font of all of the text, by number.
- SetFontSizeAll()
- Sets the size of all of the text.
- SetFontStyleAll()
- Sets the style of all of the text.
- SetLineWidth()
- Sets the width before a line wraps, or -1 for wrapping at the edge of the pane.
- SetOutlineHighlighting()
- Turns outline highlighting on or off, returning the old value.
- StopInlineSession()
- Stops the current inline session and validates the text.
- TempSelectAll()
- Temporarily seelcts all of the text, without and visual effects, until it is
restored by RestoreSelection().
- WriteToFile()
- Writes the data from the pane to a CDataFile.
Using CWASTEText with Visual Architect
If VA_COMPATIBLE_IO is defined to 1, CWASTEText has the same PutTo and GetFrom routines
as CEditText and CWASTEDlgText has the same PutTo and GetFrom routines as CDialogText.
Therefore, you can define new classes in VA with names like CVAWASTEText and
CVAWASTEDlgText that are based on CEditText and CDialogText, with library classes
CWASTEText and CWASTEDlgText. Then, you can make objects of type CVAWASTEText and
CVAWASTEDlgText in your VA views. Note that
CWASTEDlgText doesn't handle all of the validation stuff that CDialogText does.
Although I haven't tested it in a while, WASTE TCL should still theoretically support
WASTE 1.0. I strongly suggest using WASTE 1.2 instead, but if you must use WASTE 1.0,
you should use CWASTEEditTask and CWASTEStyleTask for undo support instead of
CWASTETask.
Using WASTE TCL with TCL 1.1
Romain Vignes modified the classes to work with TCL 1.1.3.
I haven't tested it out myself. You need to add the following to your prefix:
#define __LONGCOORDINATES__ 1 // Long coordinates services are
// handled by the TCL.
#define TCL_VERSION 0x01010300 // Your version of TCL
Using WASTE TCL with the WASTE Object Handlers 1.2
If WASTE_OBJECT_ARCHIVE is defined as 1, CWASTEText will use Michael Kamprath and
John Daub's WASTE Object Handler Archive for the object handlers. In this case,
you don't need to add the WASTE TCL sound icon resource (but you must include the
Object Archive one). It also adds the function InsertFSSpec() for adding a file
to the pane.
WASTE 1.2 also includes an object handler archive, which makes things a bit more
confusing. At this time, it just has sound and picture handlers, so I have not put
any support in for Marco Piovanelli's version of the handlers.
Using WASTE TCL with WASTE Tabs
If WASTE_TABS is defined as 1, CWASTEText will use the tab support code as included
with WASTE 1.2. If WASTE_AUTO_TABS is defined as 1, tab support will automatically
be installed for every CWASTEText pane. Otherwise, you must call InstallTabHandlers()
to install tab support on a pane-by-pane basis.
File I/O Options
There are currently three options for reading and writing CWASTEText panes. The first
is the WriteToFile() and ReadFromFile() functions that work with CDataFile's. They
work with files in a format similar to SimpleText, but with an additional 'SOUP'
resource that contains the object information. If you are using object I/O, there
are two different versions of the PutTo and GetFrom functions. If VA_COMPATIBLE_IO
is defined to 1, then you get functions that stream to and from files in the exact
same format as CEditText's corresponding functions. If it is defined as 0, you get
more complete functions that save and restore all of the style and object information
as well.
Demos
WASTEEdit
WASTEEdit is a slightly modified version of TinyEdit, the TCL demo supplied with
Symantec C++. I tried to do the minimum modifications necessary to get it to work,
so I haven't added any functionality. Right now, it's almost 10 times as big as WASTE
Demo, and doesn't do quite as much.
Visual Architect Demo
A simple demo of using WASTE TCL with the Visual Arcitect is included.
Acknowledgements
There have been lots of people who have helped get WASTE TCL going, and in getting the
bugs out. They include Marco Piovanelli, Mark Alldritt, jud spencer, Romain Vignes,
Micheal Grinner, Jerry Aman, Martin Fricke, Martin Sladok, Jan Petersen, Steve
Gilardi, Jim Richardson, Brian Matheny.